package homework12月9号补交.homework2.d8;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.List;

public class test {
    public static void main(String[] args) throws Exception {
        List<String> list = FileUtils.readLines(new File("D:\\ldea dashuju\\day.12.6\\src\\czxy\\homework2\\d8\\data.txt"));
        for (String s : list) {
            Class<?> aClass = Class.forName(s);
            List<String> list1 = FileUtils.readLines(new File("D:\\ldea dashuju\\day.12.6\\src\\czxy\\homework2\\d8\\data2.txt"));
            for (String s1 : list1) {
                String[] arr = s1.split("=");
                if (arr[0].equals("age")){
                    Field f = aClass.getDeclaredField(arr[0]);
                    f.setAccessible(true);
                    Constructor<?> constructor = aClass.getConstructor();
                    Object o = constructor.newInstance();
                    f.set(o,Integer.parseInt(arr[1]));
                    System.out.println(f.get(o));
                }else {
                    Field f = aClass.getDeclaredField(arr[0]);
                    f.setAccessible(true);
                    Constructor<?> constructor = aClass.getConstructor();
                    Object o = constructor.newInstance();
                    f.set(o,arr[1]);
                    System.out.println(f.get(o));
                }
            }
        }
    }
}
